import React, { Component } from 'react';
import "./recommend.css";
import service from '../../../../api';
import { withRouter } from 'react-router-dom';


class index extends Component {
    constructor (props){
        super(props)
        this.state={
            reclist:[]
            
        }
    }
    async componentDidMount() {
        var res = await service.product.pro_recommendlist({})
        console.log(res.data);
        this.setState({reclist:res.data.data},()=>{
            console.log(this.state.reclist);
        })
    }
    toDetail(index){
        console.log(index);
        console.log(this.state.reclist[index].proid);
        this.props.history.push({pathname:'/detail',state:{proid:this.state.reclist[index].proid}})
        // this.props.history.push('/detail/'+ this.state.reclist)
    }
    render() {
        return (
            <div className='recommed' >
                {
                    this.state.reclist.map((item,index)=>{
                        return (
                            <div className="good" key={index} onClick={()=>{this.toDetail(index)}}>
                                    <img src={item.img1} alt="" />
                                    <span className='desc'>{item.desc}</span>
                                    <span className="price">￥{item.originprice}</span>
                            </div>
                            
                        )
                    })
                }
            </div>
            
        );
    }
}

export default withRouter(index);